<?php
require_once 'AbstractParseMessage.class.php';

class ClassParseMessage extends AbstractParseMessage {
    
    public function reveive($title, $message) {
        // On ne fait pas de statistiques si on n'est pas dans une classe
        if( $this->name === null and $title !== 'enterClass') return;
        
        switch( $title ) {
            case 'addComment':
                $this->addComment(intval($message));
                break;
            case 'addLines':
                $this->addLines();
                break;
            case 'enterClass':
                $this->reset();
                $this->name = $message['name'];
                $this->setStatValue('line', $message['line']);
                break;
            case 'addExtends':
            case 'addImplements':
            case 'addMethodTypeHint':
            case 'addStaticReference':
            case 'addNewClassReference':
            case 'addCatchClassReference':
                $this->addStatInArray('references', $message, $message);
                break;
            case 'addCyclo':
                $this->incStats('cyclo', 1);
                break;
            case 'variableSuperglobal':
                $this->incStats('superglobal',1);
                break;
            case 'methodStat':
                $this->stats['methods'][$message['method']] = $message['stats'];
                break;
            case 'leaveClass':
                $this->sendMessage('classStat', array('class' => $this->name, 'stats' => $this->stats));
                $this->reset();
                break;
        }
    }
    
    public function reset() {
        parent::reset();
        $this->setStatValue('superglobal', 0);
        $this->setStatValue('methods', array());
        $this->setStatValue('references', array());
        $this->setStatValue('line', 0);
        
    }
    
}